//
//  NSString+FileSize.m
//  RM_IM
//
//  Created by zhangzhenyun on 2018/7/19.
//  Copyright © 2018年 user1. All rights reserved.
//

#import "NSString+FileSize.h"

@implementation NSString (FileSize)
/**KB转化为M 比例为1024 1136KB 转化为 1.11M*/
+ (NSString *)fileSizeStrFromFileSizeKB:(NSString *)fileSizeKB {
    NSRange range = [fileSizeKB rangeOfString:@"KB"];
    CGFloat fileSize = 0;
    NSString *fileSizeStr;
    if (range.location != NSNotFound) {
        fileSize = [fileSizeKB substringToIndex:range.location].floatValue;
    }
    if (fileSize >= 1024) {
        fileSize = (CGFloat)fileSize / 1024;
        fileSizeStr = [NSString stringWithFormat:@"%.2fM",fileSize];
    } else {
        fileSizeStr = fileSizeKB;
    }
    return fileSizeStr;
}
+ (NSString *)fileSizeStr:(long long)fileLength {
    CGFloat kb = (CGFloat)fileLength / 1000;
    CGFloat m = (CGFloat)(kb / 1000);
    NSString *fileSize;
    if (0 <= kb && kb < 1000) {
        fileSize = [NSString stringWithFormat:@"%.2fkb",kb];
    } else if (kb > 1000) {
        fileSize = [NSString stringWithFormat:@"%.2fMB",m];
    }
    return fileSize;
}
@end
